<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .box {
            width: 200px;
            height: 200px;
            text-align: center;
            margin: 200PX auto;
            background-color: red;
        }

        .nav {
            float: right;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <div class="box">
        我是广告
        <div class="nav">
            X
        </div>
    </div>
    <script>
        const box = document.querySelector('.box')
        const nav = document.querySelector('.nav')
        let i = 5
        const ret = setInterval(function () {
            i--
            if (i <= 0) {
                clearTimeout(ret)
                box.style.display = 'none'
            }
        }, 1000)

        nav.addEventListener('click', function () {
            box.style.display = 'none'
        })
    </script>
</body>

</html>